package com.joker.warehouse.controller;

import com.joker.common.core.domain.Result;
import com.joker.common.core.web.controller.BaseController;
import com.joker.common.security.annotation.RequiresPermissions;
import com.joker.warehouse.domain.Purchase;
import com.joker.warehouse.domain.dto.PurchaseDTO;
import com.joker.warehouse.domain.vo.PurchaseVO;
import com.joker.warehouse.service.IPurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lemon
 * @date 2025/01/13 20:59
 **/
@RestController
@RequestMapping("/purchase")
public class PurchaseController extends BaseController {

    @Autowired
    private IPurchaseService purchaseService;


    /**
     * 查询采购订单列表
     */
    @GetMapping("/list")
    public Result list(Purchase purchase)
    {
        startPage();
        List<PurchaseVO> list = purchaseService.selectPmsPurchaseList(purchase);
        return getDataTable(list);
    }

    /**
     * 商家 生成采购单
     * @param purchaseDTO 采购单
     * @return 响应
     */
    @PostMapping("/save")
    public Result save(@RequestBody PurchaseDTO purchaseDTO){
        purchaseService.save(purchaseDTO);
        return Result.success();
    }

    /**
     * 商家 审核采购单
     * @param purchaseId 采购单id
     * @param status 状态
     * @return 响应
     */
    @PutMapping("/check/{purchaseId}")
    public Result check(@PathVariable Long purchaseId,@RequestParam Integer status){
        purchaseService.check(purchaseId,status);
        return Result.success();
    }
}
